package cn.kooki.app.duobao.util;

import android.app.Activity;
import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.GridView;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;

import cn.kooki.app.duobao.R;
import cn.kooki.app.duobao.data.constant.Constants;
import cn.kooki.app.duobao.ui.Adapter.ShareDialogAdapter;

/**
 * Created by xionghao on 16/1/10.
 */
public class ShareUtils {

    private String[] titles = new String[]{
            "微信", "微信朋友圈", "微博", "QQ", "QQ空间"
    };


    private int[] imgs = new int[]{
            R.drawable.ic_share_wx, R.drawable.ic_share_wx_friend,
            R.drawable.ic_share_wb, R.drawable.ic_share_qq, R.drawable.ic_share_qzone};
    private AlertDialog alertDialog;
    private View dialogview;
    private GridView gridview;


    public interface shareItemClickLister {
        void onClick(SHARE_MEDIA media);
    }


    public void showShareDialog(final Activity context, final shareItemClickLister listener) {

        dialogview = LayoutInflater.from(context).inflate(R.layout.share_dialog, null);
        alertDialog = new AlertDialog.Builder(context).create();
        alertDialog.setCanceledOnTouchOutside(true);

        gridview = (GridView) dialogview.findViewById(R.id.share_dialog_grid_view);
        ShareDialogAdapter shareDialogAdapter = new ShareDialogAdapter(context, titles, imgs);
        gridview.setAdapter(shareDialogAdapter);
        gridview.setFocusable(true);

        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                SHARE_MEDIA media = SHARE_MEDIA.WEIXIN;

                switch (position) {
                    case 0:
                        media = SHARE_MEDIA.WEIXIN;
                        break;
                    case 1:
                        media = SHARE_MEDIA.WEIXIN_CIRCLE;
                        break;
                    case 2:
                        media = SHARE_MEDIA.SINA;
                        break;
                    case 3:
                        media = SHARE_MEDIA.QQ;
                        break;
                    case 4:
                        media = SHARE_MEDIA.QZONE;
                        break;
                }
                listener.onClick(media);
                alertDialog.dismiss();
            }
        });
        alertDialog.show();
        Window window = alertDialog.getWindow();
        window.setContentView(dialogview);
    }

}
